package com.zxx.mvpPractice.ui.fragment;

import android.app.ProgressDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.google.common.base.Preconditions;
import com.zxx.mvpPractice.R;
import com.zxx.mvpPractice.base.BaseFragment;
import com.zxx.mvpPractice.presenter.LoginFragmentPresenter;
import com.zxx.mvpPractice.presenter.MissPwdFragmentPresenter;
import com.zxx.mvpPractice.presenter.contract.LoginFragmentContract;
import com.zxx.mvpPractice.presenter.contract.MissPwdFragmentContract;
import com.zxx.mvpPractice.ui.activitys.LoginActivity;
import com.zxx.mvpPractice.utils.EventUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 用户名密码登录
 * Created by Administrator on 2016/12/30.
 */
public class MissPwdFragment extends BaseFragment<MissPwdFragmentContract.Presenter> implements MissPwdFragmentContract.View {

    @BindView(R.id.edt_username)
    EditText edt_username;
    @BindView(R.id.edt_login_code)
    EditText edt_login_code;
    @BindView(R.id.edt_login_pwd)
    EditText edt_login_pwd;
    @BindView(R.id.edt_login_repwd)
    EditText edt_login_repwd;
    private ProgressDialog dialog;
    private LoginActivity mActivity;


    @Override
    protected int getLayout() {
        return R.layout.fragment_miss_pwd;
    }


    @OnClick({R.id.bt_verification1, R.id.bt_submit_info, R.id.rl_title_left})
    void clickEvent(View view) {
        String username = edt_username.getText().toString();
        switch (view.getId()) {
            case R.id.rl_title_left:
                EventUtil.showToast(mContext, "iv_title_left");
                mActivity.jumpToLogin();
                break;
            case R.id.bt_verification1:
                mPresenter.bombRequestSms(username);
                break;
            case R.id.bt_submit_info:
                String smsCode = edt_login_code.getText().toString();
                String password1 = edt_login_pwd.getText().toString();
                String password2 = edt_login_repwd.getText().toString();
                mPresenter.bombUserUpdate(username, password1, password2, smsCode);
                break;
        }
    }

    @Override
    public boolean onBackPressedSupport() {
        mActivity.jumpToLogin();
        return true;
    }

    @Override
    protected void initView(LayoutInflater inflater) {
        mActivity = (LoginActivity) mContext;
        mPresenter = new MissPwdFragmentPresenter(this);
        dialog = new ProgressDialog(mContext);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setMessage("登陆中...");
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void showProgressDialog() {
        dialog.show();
    }

    @Override
    public void hideProgressDialog() {
        dialog.dismiss();
    }


    @Override
    public void showMessage(String text) {
        EventUtil.showToast(mContext, text);
    }

    @Override
    public void setPresenter(MissPwdFragmentContract.Presenter presenter) {
        mPresenter = Preconditions.checkNotNull(presenter);
    }

    @Override
    public void showError(String msg) {
        EventUtil.showToast(mContext, msg);
    }
}
